package com.defan.api.test;

import com.alibaba.fastjson.JSON;
import com.defan.api.utils.JSONUtils;
import com.defan.api.utils.MessUtils;
import com.defan.api.utils.RequestUtils;
import com.defan.api.utils.ShowDocUtils;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by 张俊强~ on 2017/10/17.
 */
public class DocBuilder {

    public static final String ApiKey = "03e7f5484d28dae33eaa6632dce2aa0e1415336797";
    public static final String ApiToken = "b1cc0e5117d359f29a582ea8ecc01c1675273261";

    public String url = "";
    public String method = "";
    public String paramStr = "";
    public String headerStr = "";
    public String resultText = "";


    public String TestGetResponseMess() {
        Map requestParams = new HashMap();
        String requestUrl = "http://runapi.showdoc.cc/markdown.php";
        url = "http://idmdev.cscecdf.com/DCloudApi/DBPM/taskTodoQuery/taskTodoQueryService";
        method = "POST";
        paramStr = "{\"fields\":[{\"field\":\"task_number\",\"op\":\"like\",\"value\":\"\"}],\"page\":1,\"size\":10}";
        headerStr = "{}";
        resultText = this.TestRawGetResponseMess();
        requestParams.put("url", url);
        requestParams.put("method", method);
        requestParams.put("param_str", MessUtils.TableTitle + JSONUtils.formatJsonToParamTable(paramStr));
        requestParams.put("header_str", headerStr);
        requestParams.put("result_text", JSONUtils.formatJson(resultText));

        String responseInfo = ShowDocUtils.formatToMardown(requestParams);
        System.out.println("返回的参数为：" + responseInfo);
        return responseInfo;
    }

    public String TestRawGetResponseMess() {
        Map requestHeader = new HashMap();
        String requestUrl = "http://idmdev.cscecdf.com/DCloudApi/DBPM/taskTodoQuery/taskTodoQueryService";
        String requestParam = "{\"fields\":[{\"field\":\"task_number\",\"op\":\"like\",\"value\":\"\"}],\"page\":1,\"size\":10}";
        requestHeader.put("DF_KEY", "ZTOjkhcNdwZQcCzLRexRinIsVzEArbsj");
        try {
            String responseInfo = RequestUtils.getResponseMess(requestUrl, requestParam, requestHeader);
            return responseInfo;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public void getMDResultText() {
        try {
            String responseResult = ShowDocUtils.getMDResultText(this.TestGetResponseMess(), "99", "", "", "");
            System.out.println("返回结果：" + responseResult);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
//        (new DocBuilder()).getMDResultText();
        String source = "{\"code\":\"SUCCESS\",\"data\":{\"documentId\":10897,\"docNumber\":\"YZ0002\",\"formId\":10504,\"status\":\"PROCESSING\",\"creatorCode\":\"panyixin\",\"creatorName\":\"潘一昕\",\"createTime\":\"2017-10-17 10:51\",\"organizationId\":\"C45A7019-D683-4CE1-97D1-4A207A76DA55\",\"organizationName\":\"行政管理部\",\"formName\":\"印章使用申请表\",\"formValueList\":[{\"id\":\"9b8250c7-22ef-fdd0-af63-5035c1a4395f\",\"type\":\"document-number-readonly\",\"value\":\"YZ0002\",\"displayValue\":\"YZ0002\"},{\"id\":\"3a2451b8-91ac-5fb3-8990-6d56a4265e5a\",\"type\":\"apply-date-readonly\",\"value\":\"2017-10-17 10:51\",\"displayValue\":\"2017-10-17 10:51\"},{\"id\":\"af5292a2-91f6-a4ae-621b-ff018bbabf9b\",\"type\":\"textarea-input\",\"isTitle\":false,\"isRequired\":false,\"value\":\"测试测试测试测试测试测试测试测试测试测试测试测试\",\"displayValue\":\"测试测试测试测试测试测试测试测试测试测试测试测试\"},{\"id\":\"9a07ad25-0196-55dd-36ca-c65d55cb0cbb\",\"type\":\"department-readonly\",\"value\":\"C45A7019-D683-4CE1-97D1-4A207A76DA55\",\"displayValue\":\"行政管理部\"},{\"id\":\"f362b656-4993-fe57-da5c-68d4c466a022\",\"type\":\"applicant-readonly\",\"value\":\"潘一昕\",\"displayValue\":\"潘一昕\"}],\"configList\":[{\"id\":\"9b8250c7-22ef-fdd0-af63-5035c1a4395f\",\"type\":\"document-number-readonly\",\"title\":\"编号\",\"attrCode\":\"documentNumber\",\"isRequired\":false,\"isTitle\":false,\"isPreview\":false,\"isVisiable\":false,\"width\":1,\"isPrint\":false,\"disabled\":true,\"tableConfig\":\"null\"},{\"id\":\"3a2451b8-91ac-5fb3-8990-6d56a4265e5a\",\"type\":\"apply-date-readonly\",\"title\":\"申请日期\",\"isRequired\":false,\"isTitle\":false,\"isPreview\":false,\"isVisiable\":false,\"width\":1,\"isPrint\":false,\"disabled\":true,\"tableConfig\":\"null\"},{\"id\":\"af5292a2-91f6-a4ae-621b-ff018bbabf9b\",\"type\":\"textarea-input\",\"title\":\"用印原因\",\"isRequired\":false,\"isTitle\":false,\"isPreview\":false,\"isVisiable\":false,\"width\":2,\"isPrint\":false,\"disabled\":true,\"tableConfig\":\"null\"},{\"id\":\"9a07ad25-0196-55dd-36ca-c65d55cb0cbb\",\"type\":\"department-readonly\",\"title\":\"申请部门\",\"isRequired\":false,\"isTitle\":false,\"isPreview\":false,\"isVisiable\":false,\"width\":1,\"isPrint\":false,\"disabled\":true,\"tableConfig\":\"null\"},{\"id\":\"f362b656-4993-fe57-da5c-68d4c466a022\",\"type\":\"applicant-readonly\",\"title\":\"申请人\",\"attrCode\":\"userName\",\"isRequired\":false,\"isTitle\":false,\"isPreview\":false,\"isVisiable\":false,\"width\":1,\"isPrint\":false,\"disabled\":true,\"tableConfig\":\"null\"}]}}";
        System.out.println(JSONUtils.formatJson(source));
        String result = JSONUtils.simplifyJsonArrayNumber(source, 3);
        System.out.println(JSONUtils.formatJson(result));
    }
}
//http://idmdev.cscecdf.com/DCloudApi/DBPM/queryApprovalHistory/queryApprovalHistoryService